<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

  <!--
    Maps requests to @Controllers based on @RequestMapping("path")
    annotation values If no annotation-based path mapping is found, Spring
    MVC proceeds to the next HandlerMapping (order=0 below).
  -->
  <bean
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
      <property name="interceptors">
          <list>
               <ref bean="enMeInterceptor"/>
               <ref bean="openSessionInViewInterceptor"/>
               <ref bean="setupInterceptor"/>
               <ref bean="mobileInterceptor"/>
          </list>
      </property>
     <property name="order" value="0"/>
  </bean>

  <bean id="mobileInterceptor" class="org.encuestame.mvc.interceptor.EnMeMobileInterceptor" />
  <bean id="enMeInterceptor" class=" org.encuestame.mvc.interceptor.EnMeSecurityInterceptor" />
  <bean id="setupInterceptor" class=" org.encuestame.mvc.interceptor.SetupInterceptor" />

  <bean name="openSessionInViewInterceptor"
            class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
        <property name="singleSession" value="true" />
   </bean>


  <!-- Scans for application @Components to deploy -->
  <context:component-scan base-package="org.encuestame.mvc" />

  <!--
    Enables annotated @Controllers; responsible for invoking an annotated
    POJO @Controller when one is mapped.
  -->
  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="order" value="0"/>
        <!--
            NOTE: it is important to specify the order property, so this
            adapter will be attempted before the HandlerAdapter that
            Spring MVC automatically configures. This is because a
            MappingJacksonHttpMessageConverter is registered
            automatically with the default adapter that will attempt to
            handle any Java object including BufferedImage.
        -->
        <property name="messageConverters">
            <list>
                <!-- Default converters -->
                <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>image/jpeg</value>
                        </list>
                    </property>
                </bean>
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>

                <!-- Converter for images -->
                <bean class="org.encuestame.mvc.converter.EnhancedBufferedImageHttpMessageConverter"/>

                <!-- Handle JAXB XML objects
                <bean id="marshallingHttpMessageConverter"
                 class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                    <constructor-arg>
                        <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                            <property name="classesToBeBound">
                                <list>
                                    <value>PictureFolders</value>
                                    <value>Pictures</value>
                                </list>
                            </property>
                        </bean>
                    </constructor-arg>
                </bean> -->

                <!-- This must come after our image converter
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
                -->
            </list>
        </property>
  </bean>

  <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
</beans>